﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace ChongJu.ImageAnalyze.Segmentation
{
    public class SegmentationSDK
    {

        public const string _dllName = "JY_segmentation.dll";

        /// <summary>
        /// 创建类
        /// </summary>
        /// <returns></returns>
        [DllImport(_dllName, CharSet = CharSet.Auto)]
        public static extern IntPtr CreateJY_Segmentation();


        /// <summary>
        /// 设置分割参数，参数依次为类，
        /// 前景背景分离参数，50
        /// 像素过滤参数，1000
        /// 预留参数。
        /// </summary>
        /// <param name="JY_SE"></param>
        /// <param name="threshold_segmentation"></param>
        /// <param name="eliminate_threshold"></param>
        /// <param name="a3"></param>
        /// <returns></returns>
        [DllImport(_dllName, CharSet = CharSet.Auto)]
        public static extern bool Set_Threshold(IntPtr JY_SE, int threshold_segmentation, int eliminate_threshold, int a3);


        /// <summary>
        /// 设置图片切割范围，参数依次为类，ROI参数。 默认全部为 10
        /// </summary>
        /// <param name="JY_SE"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="w"></param>
        /// <param name="h"></param>
        /// <returns></returns>
        [DllImport(_dllName, CharSet = CharSet.Auto)]
        public static extern bool Set_Img_Crop(IntPtr JY_SE, int x, int y, int w, int h);


        /// <summary>
        /// 分割图像获取接口，参数依次为类，
        /// 图像宽，
        /// 图像高，
        /// 图像通道，
        /// 输入图像指针，
        /// 指针格式化后长度，
        /// 输出图像宽，
        /// 输出图像高，
        /// 输出图像指针格式化长度，
        /// 图像旋转角度，
        /// 4个图像恢复参数。
        /// </summary>
        /// <param name="JY_SE"></param>
        /// <param name="_width"></param>
        /// <param name="_height"></param>
        /// <param name="channel"></param>
        /// <param name="input"></param>
        /// <param name="step"></param>
        /// <param name="newWidth"></param>
        /// <param name="newHeight"></param>
        /// <param name="newStep"></param>
        /// <param name="angle"></param>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="w1"></param>
        /// <param name="h1"></param>
        /// <returns></returns>
        [DllImport(_dllName, CharSet = CharSet.Auto)]
        public static extern IntPtr Get_Segmentation_img(IntPtr JY_SE, int _width, int _height, int channel, IntPtr input, int step, ref int newWidth, ref int newHeight, ref int newStep, ref double angle, ref int x1, ref int y1, ref int w1, ref int h1);
        
        
        [DllImport(_dllName, CharSet = CharSet.Auto)]
        public static extern bool White_Segmentation_img(IntPtr JY_SE, int _width, int _height, int channel, IntPtr input, int step, IntPtr path, ref double angle, ref int x1, ref int y1, ref int w1, ref int h1);


        /// <summary>
        /// 释放图像内存，参数为图像的指针
        /// </summary>
        /// <param name="data"></param>
        [DllImport(_dllName, CharSet = CharSet.Auto)]
        public static extern void FreeImage(IntPtr data);
    }
}
